package cn.kgc.mybatis.service.impl;

import cn.kgc.mybatis.entity.User;
import cn.kgc.mybatis.mapper.UserMapper;
import cn.kgc.mybatis.service.UserService;
import cn.kgc.mybatis.utils.MybatisUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 课工场
 * @date 2024/4/25
 * @description
 */
public class UserServiceImpl implements UserService {

    private UserMapper userMapper = MybatisUtil.getMapperProxy(UserMapper.class);

    public List<User>  userList(){
        List<User> users = userMapper.selectUsers();
        return users;
    }


    public Map<String,Object> userPage(Integer page,Integer limit){

        PageHelper.startPage(page,limit);
        List<User> users = userMapper.selectUsers();
        PageInfo<User> userPageInfo = new PageInfo<>(users);
        long total = userPageInfo.getTotal();

        HashMap<String, Object> result = new HashMap<>();
        result.put("total",total);
        result.put("tableData",users);

        return result;
    }
}
